#pragma once

#include "RdcBuffer.h"

#define BOOST_BIND_ENABLE_STDCALL
#include <boost/shared_ptr.hpp>

#include <atlsync.h>
#include <stdexcept>
#include <string>

namespace rdc_transport
{
    class termination_notification : public std::runtime_error
    {
    public:
        explicit termination_notification(const std::string& message)
            : std::runtime_error(message)
        {
        }
    };

    class ServerChannelCoreImpl
    {
    public:
        ServerChannelCoreImpl(std::string& channelName);
        ~ServerChannelCoreImpl();

    public:
        void Write(Buffer* pBuffer);
        void ReadFile(PCHAR pBuffer, DWORD dwInSize, PDWORD pdwOutSize);

    public:
        void Terminate();

    private:
        typedef boost::shared_ptr<boost::remove_pointer<HANDLE>::type> HandleGuard;

        HandleGuard m_connectionHandle;
        HANDLE m_hWTSFileHandle; //This handle will be closed by system.

        ATL::CEvent m_terminateEvent;
    };
}

